package com.zhongyu.service.impl;

import com.zhongyu.pojo.EmailConfig;
import com.zhongyu.service.EmailService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.ExceptionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailException;
import org.springframework.mail.SimpleMailMessage;

import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/*
发送库存预警信息
 */
@Slf4j
@Service("EmailService")
public class EmailServicelmpl implements EmailService {
     @Autowired
    public JavaMailSender emailSender;
    @Autowired
    private EmailConfig emailConfig;

    @Override
    public void sendSimpleMessage(String to, String subject, String text) {
        try {
            SimpleMailMessage message = new SimpleMailMessage();
            message.setTo(to);
            message.setFrom("sql835650975@163.com");
            message.setSubject(subject);
            message.setText(text);
            emailSender.send(message);
        } catch (MailException exception) {
            log.error(String.valueOf(ExceptionUtil.unwrapThrowable(exception)));
        }
    }
}
